package com.example.config;

import com.example.interceptor.AuthInterceptor;
import com.example.interceptor.PermissionInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class webConfig implements WebMvcConfigurer {
    @Autowired
    private AuthInterceptor authInterceptor;
    @Autowired
    private PermissionInterceptor permissionInterceptor;

    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(authInterceptor)
                .addPathPatterns("/**")//拦截所有请求
                .order(1)
                .excludePathPatterns("/login","/register");//放行登录和注册请求

        registry.addInterceptor(permissionInterceptor)
                .addPathPatterns("/**")
                .order(2)
                .excludePathPatterns("/login","/register");//放行登录和注册请求

    }
}
